import {Injectable} from '@angular/core';
import {Auth} from "../core/foundations/Auth";
import {Http} from "@angular/http";
import {Customer} from "../models/Customer";
import {url_customer as URL} from "../config";

/*
 Generated class for the CustomerAuthProvider provider.

 See https://angular.io/docs/ts/latest/guide/dependency-injection.html
 for more info on providers and Angular 2 DI.
 */
@Injectable()
export class CustomerProvider extends Auth {
  constructor(public http: Http) {
    super();
    this.apiUrl = URL;
  }



  userInfo(): Customer | null {
    return JSON.parse(super.userInfo()) as Customer;
  }

  apiToken(user?: Customer): string | null {
    if (user != null) {
      return user.api_token;
    }
    if (this.check())
      return localStorage.getItem(this.apiTokenKey);
  }

  username(user?: Customer): string | null {
    if (user != null) {
      return user.Customer_Login_ID;
    }
    if (this.check())
      return localStorage.getItem(this.usernameKey);
  }

  email(user?: Customer): string | null {
    if (user != null) {
      return user.Customer_Email;
    }
    if (this.check())
      return localStorage.getItem(this.emailKey);
  }

}
